#ifndef AUTORESP_H
#define AUTORESP_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "list.h"

/*
 * Static definitions for program attributes, such as
 * the length of sections, etc.
 */

#define SECTION_LEN 64
#define KV_LEN      128

#define INIT_VD   { {NULL, NULL}, 0, NULL, NULL}
#define INIT_KV   { {NULL, NULL}, NULL, NULL}
#define INIT_SECT { {NULL, NULL}, NULL, NULL, NULL}

#define DECL_VD(name)   vardef  name = INIT_VD
#define DECL_KV(name)   kvline  name = INIT_KV
#define DECL_SECT(name) section name = INIT_SECT

#define HSEED (1337)
#define hash(str) hash_str(str, HSEED, strlen(str))

char *errstr;
int errln;

struct t_vardef
{
    list_head lp;
    unsigned int nhash;
    char *name, *val;
};
typedef struct t_vardef vardef;

int init_vardef(char *line, vardef *init);
void free_vardef(vardef *destroy);

struct t_kvline
{
    list_head lp;
    char *keys, *vals;
    // The "keys" and "vals" pointers point to
    // multiple strings of characters separated
    // by NULL, the last element ends with a
    // double-NULL.
};
typedef struct t_kvline kvline;

int init_kvline(char *line, kvline *init);
void free_kvline(kvline *destroy);

struct t_section
{
    list_head lp;
    vardef *vdlist;
    kvline *kvlist;
    // Both lists are circularly linked with
    // the functions in list.h
    char *name;
};
typedef struct t_section section;

int init_section(char *line, vardef *vdlist, kvline *kvlist, section *init);
void free_section(section *destroy);

int init_lists(FILE *dict, section *seclist);

unsigned int hash_str(void *src, int seed, int len);

#endif
